import db from './index.js'

const { books, blt, label, note, noteList, bookshelf } = db.data
export default {
	books_list(data) {
		return books
	},
	books_get(id) {
		return books.find(p => p.id === id)
	},
	books_create(data) {
		data.id = String(books.length + 1)
		books.push(data)
		db.write()
		return data
	},
	books_update(id, data) {
		const newData = { id: id, ...data }
		books.splice(books.findIndex(p => p.id === id), 1, newData)
		db.write()
		return newData
	},
	books_delete(id) {
		books.splice(books.findIndex(p => p.id === id), 1)
		db.write()
		return true
	},
	blt_list(data) {
		return blt
	},
	label_list(data) {
		return label
	},
	note_list(data) {
		return note
	},
	// 笔记
	noteList(data) {
		return noteList
	},
	note_create(data) {
		data.id = String(note.length + 1)
		note.unshift(data)
		db.write()
		return data
	},
	bookshelf(data) {
		return bookshelf
	},
	bookshelf_create(data) {
		data.id = String(bookshelf.length + 1)
		bookshelf.push(data)
		db.write()
		return data
	},
	note_update(id, data) {
		const newData = { id: id, ...data }
		note.splice(note.findIndex(p => p.id == id), 1, newData)
		db.write()
		return newData
	},
	label_create(data) {
		data.id = String(label.length + 1)
		label.push(data)
		db.write()
		return data
	},
}